package com.kws.tool.util;

import java.security.SecureRandom;

/**
 * @author : zhangbenting
 * @date : 2024/11/13 10:55
 * @Version: 1.0
 */
public class SignUtils {

    private static final String NUMBER = "0123456789";

    private static final SecureRandom random = new SecureRandom();

    /**
     * 获取签名验证
     *
     * @param appId
     * @param timestamp
     * @param appSecret
     * @return
     */
    public static String getSignData(String appId, String appSecret, long timestamp, String nonce) {
        String value = Constant.appId + "=" + appId + "&" + Constant.appSecret + "=" + appSecret + "&" +
                Constant.nonce + "=" + nonce + "&" + Constant.timestamp + "=" + timestamp;
        return MD5Util.MD5Upper(value);
    }

    public static String generateRandomNumber(int minLength, int maxLength) {
        if (minLength < 1 || maxLength < minLength) {
            throw new IllegalArgumentException("Invalid length parameters");
        }

        int length = random.nextInt(maxLength - minLength + 1) + minLength;
        StringBuilder sb = new StringBuilder(length);

        for (int i = 0; i < length; i++) {
            int rndCharAt = random.nextInt(NUMBER.length());
            sb.append(NUMBER.charAt(rndCharAt));
        }

        return sb.toString();
    }

}
